﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class Facemillingcutterindexableinsertsarbortypeconnection
    {
        public static void _Facemillingcutterindexableinsertsarbortypeconnection(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double scale = 2; //放大系数

            
            double oal = 13.24;
            double dconms = 7.4;
            double dhub = 16.58;
            double dccb = 11.07;
            double bd = 26.57;
            double l = 3.79;
            double lccb = 1.56;
            double dc = 21.69;



            //坐标
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + oal + 4, v1.Y);
            Vector2 v3 = new Vector2(v1.X + 2 + oal / 7.397, v1.Y);
            Vector2 v4 = new Vector2(v3.X, v3.Y + dhub / 8.772);
            Vector2 v5 = new Vector2(v1.X + 1, v4.Y);
            Vector2 v6 = new Vector2(v5.X, v3.Y + dhub / 2);
            Vector2 v7 = new Vector2(v6.X + oal / 3.253 - 0.5, v6.Y);
            Vector2 v8 = new Vector2(v7.X + 0.5, v7.Y + 0.5);
            Vector2 v9 = new Vector2(v8.X, v3.Y + bd / 2);
            Vector2 v10 = new Vector2(v9.X, v9.Y * -1);
            Vector2 v11 = new Vector2(v8.X, v8.Y * -1);
            Vector2 v12 = new Vector2(v7.X, v7.Y * -1);
            Vector2 v13 = new Vector2(v6.X, v6.Y * -1);
            Vector2 v14 = new Vector2(v5.X, v5.Y * -1);
            Vector2 v15 = new Vector2(v4.X, v4.Y * -1);
            Vector2 v16 = new Vector2(v5.X + oal, v3.Y + dc / 2);
            Vector2 v17 = fun.Polar(v16, 135 * pi / 180, l);
            Vector2 v18 = fun.Polar(v16, -135 * pi / 180, l);
            Vector2 v19 = fun.Polar(v17, -135 * pi / 180, l);
            Vector2 v20 = new Vector2(v17.X - (v17.Y - v9.Y) * Math.Tan(45 * pi / 180), v9.Y);
            Vector2 v22 = new Vector2(v16.X, v16.Y * -1);
            Vector2 v23 = new Vector2(v17.X, v17.Y * -1);
            Vector2 v24 = new Vector2(v18.X, v10.Y);
            Vector2 v25 = new Vector2(v22.X - (v23.X - v24.X), v22.Y + (v24.Y - v23.Y));
            Vector2 v21 = new Vector2(v25.X, v16.Y - (v16.X - v25.X) * Math.Tan(45 * pi / 180));
            Vector2 v26 = new Vector2(v16.X - (v16.X - v19.X) / 2, v16.Y);
            Vector2 v27 = new Vector2(v25.X, v2.Y + dccb / 2);
            Vector2 v28 = new Vector2(v27.X - lccb, v27.Y);
            Vector2 v29 = new Vector2(v27.X, v27.Y * -1);
            Vector2 v30 = new Vector2(v28.X, v29.Y);
            Vector2 v31 = new Vector2(v28.X, v2.Y - dconms / 2);
            Vector2 v32 = new Vector2(v14.X, v31.Y);
            Vector2 v33 = new Vector2(v31.X, v31.Y * -1);
            Vector2 v34 = new Vector2(v6.X, v33.Y);
            Vector2 a1 = new Vector2(v5.X, v1.Y);
            Vector2 a2 = new Vector2(v25.X, v1.Y);




            //作图
            //1
            Line line1 = new Line(v1, v2);
            line1.Layer = centre;
            line1.Linetype = Linetype.DashDot;
            line1.LinetypeScale = 3;
            dxf.AddEntity(line1);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v8));
            line2.Vertexes.Add(new LwPolylineVertex(v7));
            line2.Vertexes.Add(new LwPolylineVertex(v6));
            line2.Vertexes.Add(new LwPolylineVertex(v5));
            line2.Vertexes.Add(new LwPolylineVertex(v4));
            line2.Vertexes.Add(new LwPolylineVertex(v15));
            line2.Vertexes.Add(new LwPolylineVertex(v14));
            line2.Vertexes.Add(new LwPolylineVertex(v13));
            line2.Vertexes.Add(new LwPolylineVertex(v12));
            line2.Vertexes.Add(new LwPolylineVertex(v11));
            line2.Vertexes[0].Bulge = Math.Tan(-85 * pi / 180 / 4);
            line2.Vertexes[8].Bulge = Math.Tan(-85 * pi / 180 / 4);
            fun.PolyFill(dxf, line2, 0.1, contour);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v20));
            line3.Vertexes.Add(new LwPolylineVertex(v9));
            line3.Vertexes.Add(new LwPolylineVertex(v10));
            line3.Vertexes.Add(new LwPolylineVertex(v24));
            line3.Vertexes.Add(new LwPolylineVertex(v25));
            line3.Vertexes.Add(new LwPolylineVertex(v22));
            line3.Vertexes.Add(new LwPolylineVertex(v23));
            line3.Vertexes.Add(new LwPolylineVertex(v24));
            fun.PolyFill(dxf, line3, 0.1, contour);

            LwPolyline line4 = new LwPolyline();
            line4.Vertexes.Add(new LwPolylineVertex(v18));
            line4.Vertexes.Add(new LwPolylineVertex(v16));
            line4.Vertexes.Add(new LwPolylineVertex(v17));
            line4.Vertexes.Add(new LwPolylineVertex(v19));
            line4.Vertexes.Add(new LwPolylineVertex(v18));
            line4.Vertexes.Add(new LwPolylineVertex(v24));
            line4.Vertexes.Add(new LwPolylineVertex(v25));
            line4.Vertexes.Add(new LwPolylineVertex(v21));
            fun.PolyFill(dxf, line4, 0.1, contour);

            Line line5 = new Line(v34, v33);
            line5.Layer = refin;
            line5.Linetype = Linetype.Dashed;
            line5.LinetypeScale = 5;
            dxf.AddEntity(line5);

            Line line6 = new Line(v32, v31);
            line6.Layer = refin;
            line6.Linetype = Linetype.Dashed;
            line6.LinetypeScale = 5;
            dxf.AddEntity(line6);

            Line line7 = new Line(v27, v28);
            line7.Layer = refin;
            line7.Linetype = Linetype.Dashed;
            line7.LinetypeScale = 5;
            dxf.AddEntity(line7);

            Line line8 = new Line(v30, v29);
            line8.Layer = refin;
            line8.Linetype = Linetype.Dashed;
            line8.LinetypeScale = 5;
            dxf.AddEntity(line8);

            Line line9 = new Line(v28, v30);
            line9.Layer = refin;
            line9.Linetype = Linetype.Dashed;
            line9.LinetypeScale = 5;
            dxf.AddEntity(line9);


            fun.drawcircle(dxf, v26, l / 5.414, 0.1, contour);


            //坐标系
            fun.Axis(dxf, a1, -90, 180, "", "", "", 0.3, 1, 0);

            fun.Axis(dxf, a2, -90, 180, "", "", "", 0.3, 1, 0);



            //标注

            double height = 2;
            double arrowsize = 2;
            double exline = 2;

        
            fun.dimrot1(dxf, v6, v16, 0, oal, 1, height, arrowsize, exline, "OAL,LPR,LF,LTA", "", "");

            fun.dimrot1(dxf, v28, v27, 0, dconms / 4, 1, height, arrowsize, exline, "LCCB", "", "");

            fun.dimrot1(dxf, v34, v32, 90, dconms, 1, height, arrowsize, exline, "DCONMS", "", "");

            fun.dimrot1(dxf, v6, v13, 90, dconms, 1, height, arrowsize, exline, "DHUB", "", "");

            fun.dimrot1(dxf, v29, v27, -90, dconms, 1, height, arrowsize, exline, "DCCB", "", "");

            fun.dimrot1(dxf, v22, v16, -90, dconms * 1.5, 1, height, arrowsize, exline, "DC", "", "");

            fun.dimrot1(dxf, v20, v24, -90, dconms * 2.5, 1, height, arrowsize, exline, "BD", "", "");

            fun.dimrot1(dxf, v17, v23, -90, dconms * 3, 1, height, arrowsize, exline, "DCX", "", "");

            fun.dimrot1(dxf, v22, v23, 180, dconms , 1, height, arrowsize, exline, "APMX", "", "");

            fun.jdbz2(dxf, new Line(v16, fun.Polar(v16, 90 * pi / 180, 0.1)), new Line(v16, fun.Polar(v16, 135 * pi / 180, 0.1)), oal / 2, height, arrowsize, exline, "KAPR", "", "");






            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

    }
}